set more off
use "$build/iv_fin_strain.dta", clear

local clusteroption="judgeXyear"
local instrument="stringency_n100_loo"
local fe="districtXquarter"

macro define controls="nopriorcases joint ad_damnum ageatcase age_sq age_cub fem1 fem1_miss neigh_pov_rate_5yr nbrhd_med_rent_5yr neigh_pov_rate_5yr_miss nbrhd_med_rent_5yr_miss VANTAGE_V3_SCORE_b1_8 VANTAGE_V3_SCORE_b1_8_miss"
macro define controls_test="nopriorcases=joint=ad_damnum=ageatcase=age_sq=age_cub=fem1=fem1_miss=neigh_pov_rate_5yr=nbrhd_med_rent_5yr= neigh_pov_rate_5yr_miss=nbrhd_med_rent_5yr_miss=VANTAGE_V3_SCORE_b1_8=VANTAGE_V3_SCORE_b1_8_miss"

replace age_sq=age_sq/1000
replace age_cub=age_cub/1000

label var age_sq "Age$^2$/1000"
label var age_cub "Age$^3$/1000"

***********************
*Test of Randomization*
***********************
eststo rand1: areg evicted $controls, r cluster(`clusteroption') a(`fe')
	local obs1: di %12.2gc e(N)
	estadd local obs "`obs1'", replace
	test $controls_test
	estadd scalar F=r(F), replace
	estadd scalar p=r(p), replace

eststo rand2: areg `instrument' $controls, r cluster(`clusteroption')  a(`fe')
	local obs1: di %12.2gc e(N)
	estadd local obs "`obs1'", replace
	test $controls_test
	estadd scalar F=r(F), replace
	estadd scalar p=r(p), replace	

*****************
*Export to Latex*
*****************
esttab  rand1 rand2  using "${Inputs}/Cook_experian_balance.tex", ///
replace compress nodepvars wrap booktabs nonotes label  se(5) b(5) ///
eqlabels(none) keep( $controls ) star(* 0.10 ** 0.05 *** 0.01) ///
stats(obs F p, fmt(3 3 3)  labels( `"Number of observations"' `"Joint F-Test Stat."' `"p-value"') ) ///
mtitles("Evicted" "Judge Stringency") 
